package logic

import (
	"context"
	"user/models/mysql"

	"user/internal/svc"
	"user/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListLogic) List(in *user.ListRequest) (*user.ListResponse, error) {
	// todo: add your logic here and delete this line

	var list []mysql.House
	mysql.DB.Debug().Model(&list).Find(&list)

	var Slice []*user.ListSlice

	for _, lists := range list {
		Show := &user.ListSlice{
			Id:      int64(lists.ID),
			Address: lists.Address,
			Area:    lists.Area,
			Rent:    int64(lists.Rent),
		}
		Slice = append(Slice, Show)
	}

	return &user.ListResponse{List: Slice}, nil
}
